import { tagShopList } from '@/api/tag'

export default {
  data() {
    const _self = this
    return {
      tagShopListCascadeProps: {
        multiple: true,
        value: 'id',
        label: 'name',
        // emitPath: false,
        emitPath: true,
        lazy: true,
        async lazyLoad(node, resolve) {
          const { level, value } = node
          const manageShopList = JSON.parse(JSON.stringify(_self.manageShopList))
          if (level === 1) {
            let list = []
            if (value === 'all') {
              list = manageShopList
            } else {
              const params = { tags: [value] }
              const { data } = await tagShopList(params)
              list = data || []
            }
            list = list.filter(v => {
              v.leaf = true
              return _self.allFilterIds.shopIds.includes(v.id)
            })
            if (!list.length) {
              _self.tagListOptions.some((v, i) => {
                if (v.id === value) {
                  v.disabled = true
                  v.name = v.name + '(无标记门店)'
                  _self.$forceUpdate()
                  return true
                }
              })
            }
            resolve(list)
          } else {
            resolve([])
          }
        }
      }
    }
  },
  methods: {}
}
